{% import "macro.html.twig" as web_macro %}
{% import "admin-v2/macro.html.twig" as admin_macro %}
{% import _self as self_macro %}

{% set menu = menu|default(null) %}
{% set currentMenu = permission(menu) %}
{% set cloudSmsInfo = isOldSmsUser()|default(false) %}
{% set lang = app.request.getLocale() %}
{% set isSafari = (app.request.headers.get('User-Agent') matches '/Safari/') and (not (app.request.headers.get('User-Agent') matches '/Chrome/')) %}

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->
<html lang="{{ lang }}" class="{% if lang == 'en' %}es-en-admin{% endif %}">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="renderer" content="webkit">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta content="{{ csrf_token('site') }}" name="csrf-token" />
  <title>

    {% block title %}
      {{ currentMenu.name|trans({}, 'menu') }}
      - {{ menu|parent_permission.name|trans({}, 'menu') }} -
        {{ menu|parent_permission.code|parent_permission.name|trans({}, 'menu')  }}
    {% endblock %}
    {% if not setting('copyright.owned') %} | EduSoho{% endif %}
  </title>

  {% if setting('site.favicon') %}
    <link rel="icon" href="{{ asset(setting('site.favicon')) }}" type="image/x-icon" />
    <link href="{{ asset(setting('site.favicon')) }}" rel="shortcut icon" />
  {% endif %}

  {% block stylesheets %}
  <link href="{{ asset('assets/libs/gallery2/bootstrap/3.1.1/css/bootstrap.css') }}" rel="stylesheet" />
  <link href="{{ asset('static-dist/app/css/admin.css') }}" rel="stylesheet" />
  <link href="{{ asset('static-dist/app/css/admin-v2.css') }}" rel="stylesheet" />
  {% endblock %}

  {% block javascripts %}{% endblock %}
  <!--[if lt IE 9]>
    <script src="{{ asset('assets/libs/html5shiv.js') }}"></script>
    <script src="{{ asset('assets/libs/respond.min.js') }}"></script>
  <![endif]-->
    <script src="{{ asset('assets/libs/jquery/1.11.2/jquery-admin-v2.js') }}"></script>
    <script src="{{ asset('assets/libs/gallery2/bootstrap/bootstrap.js') }}"></script>
</head>
{% block body %}
  <body {% if bodyClass|default('') %}class="{{ bodyClass }}"{% endif %}>
    <!--[if lt IE 9]>
      {% include 'default/ie8-alert.html.twig' %}
    <![endif]-->
    <div class="ct-layout-container admin-layout-container">
      <div class="cd-fixed-top">
        <div class="ct-top-logo hidden-xs">
          <a class="admin-navbar-brand" href="{{ url('admin_v2') }}">{% if not setting('copyright.owned') %}EduSoho{% endif %}{{'admin.navbar.header.console_btn'|trans}}</a>
        </div>
        <div class="navbar-header navbar-header--mobile visible-xs">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <i class="es-icon es-icon-menu"></i>
          </button>
          <a class="navbar-mobile-title" href="{{ url('admin_v2') }}">{{'admin.navbar.header.console_btn'|trans}}</a>
        </div>
        <div class="ct-layout-navbar navbar-collapse navbar-collapse--mobile collapse">
          {% include 'admin-v2/widget/navigation.html.twig' %}
        </div>
        <div class="ct-layout-person hidden-xs">
          <ul class="cd-clearfix ct-layout-person__ul mb0">
            <li class="ct-layout-person_center cd-dropdown" data-toggle="cd-dropdown">
                <a class="user-avatar-toggle" href="javascript:;">
                  <img class="cd-avatar cd-avatar-xs" src="{{ filepath(app.user.smallAvatar, 'avatar.png') }}">
                  <span class="cd-ml8">{{ app.user.nickname }}</span>
                </a>
                <div class="dropdown-menu user-dropdown">
                  <div class="text-center ptl">
                    <div class="dropdown-arrow"></div>
                    <a class="user-operate-link" href="{{ path('logout') }}"><i class="es-icon es-icon-logout cd-mr8"></i>{{ 'homepage.header.logout'|trans }}</a>
                  </div>
                </div>
            </li>
          </ul>
        </div>
        <div class="pull-right change-version-btn">
          <a href="{{ path('homepage') }}" target="_blank"><i class="es-icon es-icon-site icon-home"></i>{{ 'admin_v2.homepage.school_info.access_web'|trans }}</a>
        </div>
      </div>
      <div class="cd-layout-main">
        {% if isSafari %}
          {% include 'admin-v2/default/safari-notify-modal.html.twig' %}
        {% endif %}
        {% block container %}
          {% block content %}
            {% include 'admin-v2/widget/side-bar.html.twig' %}
            <div class="cd-layout-aside">
              <div class="cd-layout-aside_bread"></div>
              <div class="cd-layout-adside_content">
                <div class="page-header clearfix pvm">
                  {% block page_flash_message %}{% endblock %}
                  <h1 class="pull-left">
                      {% block page_title %}
                          {{ currentMenu.code|parent_permission.name|trans({}, 'menu') }}
                      {% endblock %}
                  </h1>
                  <div class="pull-right">

                      {% block page_buttons %}


                        {% if currentMenu.mode|default('') == 'capsules' and capsule|default(false) %}
                          {% for m in sub_permissions(permission(capsule).code,'topBtn') if m.visible is not defined or eval_expression(m.visible) %}
                            {{ self_macro.menu_link_html(_context, m, 'btn btn-success btn-sm') }}
                          {% endfor %}
                        {% else %}
                          {% for m in sub_permissions(currentMenu.code,'topBtn') if m.visible is not defined or eval_expression(m.visible) %}
                            {% set class = m.class|default() ? "btn btn-sm " ~  m.class : 'btn btn-success btn-sm' %}
                            {{ self_macro.menu_link_html(_context, m, class) }}
                          {% endfor %}
                        {% endif %}
                      {% endblock %}

                  </div>
                </div>
                {% block content_header %}{% endblock %}
                {% block tabs %}{% include 'admin-v2/widget/tabs.html.twig' %}{% endblock %}
                {% block capsule %}{% endblock %}
                {% block main %}
                {% endblock %}
              </div>
            </div>
          {% endblock %}
        {% endblock %}
      </div>
    </div>


    {% block footer %}
      <div class="site-analytics-section">
        {{ setting('site.analytics')|raw }}
      </div>

      {% if setting('siteTrace.enabled')|default(false) %}
        {{ setting('siteTrace.script')|raw }}
      {% endif %}
    {% endblock %}


    <div id="modal" class="modal" ></div>
    <div id="attachment-modal" class="modal" ></div>
    {% if setting('copyright.thirdCopyright') != 1 and is_saas() %}
      <div class="fixed-bar">
        <a href="{{path('feedback')}}"  target='_blank' class="icon-question-text feedback">
          <span>{{ 'admin.fixed_bar.product_feedback'|trans|raw }}</span>
        </a>
      </div>
    {% endif %}

    {% block scriptBoot %}
      {% include 'old-script_boot.html.twig' with {script_main: asset('bundles/topxiaadmin/js/admin-app-v2.js')} %}
      {% include 'admin-v2/default/script-webpack.html.twig' %}
      {% include 'admin-v2/script_boot.html.twig'  with {state :0} %}
    {% endblock %}

    {% block faqSDK %}
      {% include 'admin-v2/faq/sdk.html.twig' %}
    {% endblock %}
  </body>
{% endblock %}
</html>

{% macro menu_link_html(_context, menu, class) %}
  <a
  {% if class %}
    class="{{ class }}"
  {% endif %}
  {% if menu.mode|default(null) == 'modal' %}
    data-url="{{ permission_path(menu) }}"
    data-toggle="modal"
    data-target="#modal"
  {% else %}
    href="{{ permission_path(menu) }}"
  {% endif %}
  {% if menu.blank|default(false) %}
    target="blank"
  {% endif %}
  >{{ menu.name|trans({}, 'menu') }}</a>
{% endmacro %}